<?php 
/**
 *
 DROP TABLE IF EXISTS `dict_circle_user`;
CREATE TABLE `dict_circle_user` (
  `c_id` int(10) unsigned NOT NULL,
  `u_id` int(10) unsigned NOT NULL,
  `degree` tinyint(4) DEFAULT '0',
  PRIMARY KEY (`c_id`,`u_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
 */
Class CircleUserModel extends Model{
  protected $_link = array(
              "Document" => array(
                  "mapping_type"  => BELONGS_TO,
                  'class_name'    => "Document",
                  'foreign_key'   => "c_id",
                  "mapping_fields" => "d_id, docname"
                  ),
                    );

  public function addCircleUser($data)
  {
      return $this->add($data);
  }

  public function selectAllUserByCid(int $c_id)
  {
      $model = new Model();
      return $model->query("SELECT dcu.u_id, degree, createtime, username  FROM 
                            dict_circle_user dcu
                            LEFT JOIN dict_user du on dcu.u_id = du.u_id
                            WHERE dcu.c_id = $c_id
                            order by degree desc");
  }

  public function delCircleUser(int $c_id, int $u_id)
  {
      return $this->where('c_id=' . $c_id . ' and u_id=' . $u_id)->delete();
  }
}
 ?>